package com.shenchuangit.wma.ui;

import com.shenchuangit.wma.ui.panel.layout.CenterPanel;
import com.shenchuangit.wma.ui.panel.layout.LeftPanel;

import javax.swing.*;
import java.awt.*;

/**
 * 主窗体
 * @author dpf
 */
public class MainFrame extends JFrame {
    public static int frameWidth;
    public static int frameHeight;
    public static int leftWidth;
    public static int rightWidth;

    /**
     * 创建并显示GUI。出于线程安全的考虑，
     * 这个方法在事件调用线程中调用。
     */
    public void init() {
        this.setSize(900,600);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setUndecorated(true) ;
        this.setLocationRelativeTo(null);

        this.initSize();

        this.initFrameLayout();

        this.setVisible(true);
    }

    /**
     * 初始化尺寸
     */
    public void initSize() {
        MainFrame.frameWidth = this.getWidth();
        MainFrame.frameHeight = this.getHeight();
        MainFrame.leftWidth = MainFrame.frameWidth*2/10;
        MainFrame.rightWidth = MainFrame.frameWidth-MainFrame.leftWidth;
    }

    /**
     * 初始化布局
     */
    public void initFrameLayout() {
        this.setLayout(new BorderLayout());

        LeftPanel leftPanel = new LeftPanel(leftWidth, frameHeight);
        leftPanel.init();
        this.add(leftPanel, BorderLayout.WEST);

        CenterPanel centerPanel = new CenterPanel();
        centerPanel.init();
        centerPanel.setCloseListener(this);
        this.add(centerPanel, BorderLayout.CENTER);

        leftPanel.setCenterPanel(centerPanel);
    }

}
